package com.situ.mall.service.impl;

import com.situ.mall.mapper.CategoryMapper;
import com.situ.mall.pojo.Category;
import com.situ.mall.service.ICategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CategoryServiceImpl implements ICategoryService {
    @Autowired
    private CategoryMapper categoryMapper;

    @Cacheable(value = "category", key = "#root.methodName")
    @Override
    public List<Category> selectTopCategory() {
        return categoryMapper.selectTopCategory();
    }

    @Cacheable(value = "category", key = "#root.methodName + ':' + #id")
    @Override
    public List<Category> selectSecondCategoryByTopCategoryId(Integer id) {
        return categoryMapper.selectSecondCategoryByTopCategoryId(id);
    }

    @Override
    public int selectTopCategoryIdByCategoryId(Integer categoryId) {
        return categoryMapper.selectTopCategoryIdByCategoryId(categoryId);
    }
}
